﻿@model Perfect.MVC.PFProvinceCityBox
@{
    //string sf = ViewData["sf"] as string;
    //string city = ViewData["city"] as string;
    //string county = ViewData["county"] as string;
    //string sfField = ViewData["sfField"] as string;
    //string cityField = ViewData["cityField"] as string;
    //var sfList = (List<KeyValuePair<object, object>>)ViewData["sfList"];
    //var cityList = (List<KeyValuePair<object, object>>)ViewData["cityList"];

    string sf = Model.ProvinceValue as string;
    string city = Model.CityValue as string;
    ////string county = ViewData["county"] as string;
    var sfList = (List<KeyValuePair<object, object>>)Model.ProvinceList;
    var cityList = (List<KeyValuePair<object, object>>)Model.CityList;

}
<script type="text/javascript">
    var paging = {};
    var sf = "@(sf)";
    var city = "@(city)";
    $(document).ready(function () {
        //$('.' + contentClass + ' select').iSelect();
        
        var ddlsf = $("#sf");
        var ddlcity = $("#city");
        //var ddlcounty = $("#county");

        //function clearCounty() {
        //    ddlcounty.empty();
        //    $("#_iSelVal_" + ddlcounty[0].id).text('请选择');
        //}
        function clearCity() {
            ddlcity.empty();
            $("#_iSelVal_" + ddlcity[0].id).text('请选择');
            //clearCounty();
        }
        ddlsf.change(function () {
            // 先清空第二个
            clearCity();
            // 实际的应用中，这里的option一般都是用循环生成多个了
            $pf.post('/Hyzl/Home/GetCityBySF?sf=' + ddlsf.val(), null, function (data) {
                if (data.Data) {
                    $("<option disabled='disabled' selected='selected'></option>")
                    .val('')
                    .text('请选择')
                    .appendTo(ddlcity);
                    $.each(data.Data, function (i, item) {
                        $("<option></option>")
                        .val(item["Key"])
                        .text(item["Value"])
                        .appendTo(ddlcity);
                    });
                }
            });
        });

        //ddlcity.change(function () {
        //    // 先清空第二个
        //    //clearCounty();
        //    // 实际的应用中，这里的option一般都是用循环生成多个了
        //    $pf.post('/Hyzl/Home/GetCountyByCity?sf=' + ddlsf.val() + '&city=' + encodeURI(ddlcity.val()), null, function (data) {
        //        if (data.Data) {
        //            $("<option disabled='disabled' selected='selected'></option>")
        //            .val('')
        //            .text('请选择')
        //            .appendTo(ddlcounty);
        //            $.each(data.Data, function (i, item) {
        //                $("<option></option>")
        //                .val(item["Key"])
        //                .text(item["Value"])
        //                .appendTo(ddlcounty);
        //            });
        //        }
        //    });
        //});

        //function doSearch() {
        //    var county = ddlcounty.val() || '';//只选市时,county要传空字符串
        //    tableApi.loadUrl(encodeURI('/Hyzl/Home/GetAgentByArea?sf=' + ddlsf.val() + '&city=' + ddlcity.val() + '&county=' + county), {
        //    });
        //}
        //ddlcity.change(function () {
        //    doSearch();
        //});
        //ddlcounty.change(function () {
        //    doSearch();
        //});


    });
</script>
<div class="kv-item ">
    @Html.BuildLabel(Model.ProvinceField)
    <div class="kv-item-content ">
        @Html.BuildDropDownList(Model.ProvinceField, Model.ProvinceValue, a => { a.SetSelectList(sfList); if (!string.IsNullOrWhiteSpace(sf)) { a.SetSelectedValue(sf); } })
    </div>
</div>
<div class="kv-item ">
    @Html.BuildLabel(Model.CityField)
    <div class="kv-item-content ">
        @Html.BuildDropDownList(Model.CityField, Model.CityValue, a => { a.SetSelectList(cityList); if (!string.IsNullOrWhiteSpace(city)) { a.SetSelectedValue(city); } })
    </div>
</div>
@*<div class="kv-item ">
    @Html.BuildLabel(sfField)
    <div class="kv-item-content ">
        @Html.BuildDropDownList(sfField, null, a => { a.SetSelectList((List<KeyValuePair<object, object>>)ViewData["sfList"]); if (!string.IsNullOrWhiteSpace(sf)) { a.SetSelectedValue(sf); } })
    </div>
</div>
<div class="kv-item ">
    @Html.BuildLabel(cityField)
    <div class="kv-item-content ">
        @Html.BuildDropDownList(cityField, null, a => { a.SetSelectList((List<KeyValuePair<object, object>>)ViewData["cityList"]); if (!string.IsNullOrWhiteSpace(city)) { a.SetSelectedValue(city); } })
    </div>
</div>*@

@*<div class="kv-item address">
    @Html.BuildLabel("county")
    <div class="kv-item-content ">
        @Html.BuildDropDownList("county", null, a => { a.SetSelectList((List<KeyValuePair<object, object>>)ViewData["countyList"]); if (!string.IsNullOrWhiteSpace(county)) { a.SetSelectedValue(county); } })
    </div>
</div>*@